package com.hua.api.modules.express.rest;

import com.hua.api.core.framework.annotation.AnonymousAccess;
import com.hua.api.core.framework.annotation.TokenCheck;
import com.hua.api.core.framework.config.scurity.TokenHelper;
import com.hua.api.core.framework.util.Result;
import com.hua.api.modules.express.service.ExpressOrderService;
import com.hua.api.modules.express.service.ShopInfoExpressService;
import com.hua.api.modules.express.service.dto.ExpressInfoCriteria;
import com.hua.api.modules.express.service.dto.ExpressOrderDto;
import com.hua.api.modules.order.service.dto.OrderInfoCriteria;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/expressOrder")
public class ExpressOrderController {

    public final ShopInfoExpressService  shopInfoExpressService;

    public final ExpressOrderService expressOrderService;

    // 物流订单计费
    @AnonymousAccess
    @RequestMapping("/orderCalculate/{orderId}/{expressId}")
    public Result orderCalculate(@PathVariable Integer orderId, @PathVariable Integer expressId,Integer isSaleAfter) {
        isSaleAfter = null==isSaleAfter?0:isSaleAfter;
        return Result.of(shopInfoExpressService.orderCalculate(orderId,expressId,isSaleAfter));
    }

    // 物流提交订单
    @AnonymousAccess
    @RequestMapping("/orderPlace/{expressOrderNo}")
    public Result orderPlace(@PathVariable String expressOrderNo) {
        return Result.of(shopInfoExpressService.orderPlace(expressOrderNo));
    }

    // 物流单加价
    @AnonymousAccess
    @RequestMapping("/addition")
    public Result addition(ExpressInfoCriteria criteria) {
        return Result.of(shopInfoExpressService.addition(criteria,TokenHelper.getUserInfo()));
    }

    // 取消物流单
    @AnonymousAccess
    @RequestMapping("/abortOrder")
    public Result abortOrder(ExpressInfoCriteria criteria) {
        shopInfoExpressService.abortOrder(criteria);
        return Result.success();
    }

    // 订单自配送录入
    @RequestMapping("/self/create/{orderNo}")
    @TokenCheck(userAgent = "selfCreate")
    public Result selfCreate(@PathVariable String orderNo, @RequestBody ExpressOrderDto dto){
        expressOrderService.createSelfExpressOrder(orderNo,dto,TokenHelper.getUserInfo().getUserId());
        return Result.success();
    }

}
